﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Modeling_Sub_Pages_NewsPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        UniversityDatabaseManagerment udm = new UniversityDatabaseManagerment();
        
        try
        {
            if (udm.createConnection() != null)
            {
                if (!IsPostBack)
                {
                    ddlDepartment.DataSource = udm.showDepartment(udm.createConnection());
                    ddlDepartment.DataTextField = "Name";
                    ddlDepartment.DataValueField = "ID";
                    ddlDepartment.DataBind();
                    ddlDepartment.Items.Insert(0, new ListItem("All Department", "-1"));

                    ProductDataList2.DataSource = udm.showFaculty(udm.createConnection(), -1);
                    ProductDataList2.DataBind(); 
                }
            }
            else
            {
                Response.Redirect("~/ErrorPage.aspx");
            }
        }
        catch (Exception)
        {
            Response.Redirect("~/ErrorPage.aspx");
        }
    }
    protected void ProductDataList2_PagePropertiesChanged(object sender, EventArgs e)
    {
        ProductDataList2.DataBind(); 
    }
    protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e)
    {
        UniversityDatabaseManagerment udm = new UniversityDatabaseManagerment();

        int type = Convert.ToInt32(ddlDepartment.SelectedValue.ToString());

        ProductDataList2.DataSource = udm.showFaculty(udm.createConnection(), type);
        ProductDataList2.DataBind(); 
    }
}